<template>

  <div class="container">
    <el-row>
      <el-button-group class="right-but" style="display:flex;">
        <el-button type="text" @click="refreshList" style="cursor:pointer;margin-right:-13px">
          <img style="width:44px;height:36px;" src="~@/assets/img/shuaxin.png">
        </el-button>
        <PopoverBut :checkedProps="checkedProps" style="cursor:pointer;" :options="options"
                    @getCheckeds="handlerCloumn"></PopoverBut>
      </el-button-group>
    </el-row>
    <el-table
        size="mini"
        v-loading="loading"
        :data="tableData"
        style="width: 100%;margin-top:10px"
        border
        :header-cell-style="{
        'background-color': '#eeeeee !important',
      }"
        :row-class-name="tableRowClassName"
    >
      <el-table-column type="index" label="序号" width="70" align="center">
        <template slot-scope="scope">
          <span>{{
              (page.pageNo - 1) * page.pageSize + scope.$index + 1
            }}</span>
        </template>
      </el-table-column>
      <el-table-column
          prop="applyDate"
          label="订阅日期"
          :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
          prop="modularNames"
          label="本次订阅模块"
          :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
          prop="enableDate"
          label="开通日期"
          :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          {{ scope.row.enableDate|noValue }}
        </template>
      </el-table-column>
      <span v-for="(item, index) in checkedProps" :key="index">
              <el-table-column prop="updateBy.loginName" :label="item" v-if="item==='创建人'">
                  <template slot-scope="scope">
                      <span v-if="scope.row.createBy && scope.row.createBy.loginName">
                           {{ scope.row.createBy.loginName | noValue }}
                      </span>
                      <span v-else>--</span>
                  </template>
              </el-table-column>
              <el-table-column prop="createDate" :label="item" v-if="item==='创建时间'"></el-table-column>
              <el-table-column prop="updateBy.loginName" :label="item" v-if="item==='上次操作人'">
                  <template slot-scope="scope">
                      <span v-if="scope.row.createBy && scope.row.createBy.loginName">
                           {{ scope.row.createBy.loginName | noValue }}
                      </span>
                      <span v-else>--</span>
                  </template>
              </el-table-column>
              <el-table-column prop="updateDate" :label="item" v-if="item==='上次操作时间'"></el-table-column>
            </span>
      <el-table-column
          prop="state"
          label="状态"
          sortable="custom"
          width="120px"
      >
        <template slot-scope="scope">
          <div class="state invalid" >
            <span></span>{{ $dictUtils.getDictLabel("modularState", scope.row.state, "") }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作" width="108px">
        <template slot-scope="scope">
          <el-link
              v-if="hasPermission('company:company:edit')&& scope.row.state===1"
              type="primary"
              :underline="false"
              @click="edit(scope.row)"
          >撤销申请
          </el-link
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-size="page.pageSize"
        :current-page="page.pageNo"
        layout="total,sizes,prev, pager, next, jumper"
        :total="page.total"
    >
    </el-pagination>
  </div>
</template>
<script>
import {modularApplyList, updateModularApply} from '@/api/modular/modular.js'
import PopoverBut from '@/components/button/popoverBut'

const options1 = []
export default {
  components: {
    PopoverBut
  },
  data () {
    return {
      checkedProps: options1,
      options: [
        {
          label: '创建人',
          key: 'createBy.loginName'
        },
        {
          label: '创建时间',
          key: 'createDate'
        },
        {
          label: '上次操作人',
          key: 'updateBy.loginName'
        },
        {
          label: '上次操作时间',
          key: 'updateDate'
        }],
      loading: false,
      orderBy: {
        name: 'update_date',
        method: 'desc'
      },
      page: {
        pageSize: 10,
        pageNo: 1,
        total: 0
      },
      tableData: []
    }
  },
  methods: {
    // 获取列表带分页
    modularApplyList (params, props, orderName, orderByAORC, queryNames, queryState) {
      this.loading = true
      modularApplyList({
        pageSize: params.pageSize,
        pageNo: params.pageNo,
        props: props,
        orderBy: orderName,
        orderByAORC: orderByAORC,
        names: queryNames,
        state: queryState

      }).then((res) => {
        if (res.data.code === '200') {
          this.tableData = res.data.result.list
          this.page.total = res.data.result.count
        }
        this.loading = false
      })
    },
    // 获取数据列表
    refreshList () {
      this.loading = true
      this.$http({
        url: '/sys/user/list',
        method: 'get',
        params: {
          'pageNo': this.pageNo,
          'pageSize': this.pageSize,
          'orderBy': this.orderBy,
          ...this.searchForm
        }
      }).then(({
                 data
               }) => {
        if (data && data.success) {
          this.dataList = data.page.list
          this.total = data.page.count
          this.loading = false
        }
      })
    },
    // 是否显示某列数据
    handlerCloumn (e) {
      this.checkedProps = e
    },
    tableRowClassName ({row, rowIndex}) {
      if (rowIndex % 2 === 1) {
        return 'warning-row'
      } else {
        return 'success-row'
      }
    },
    // 编辑
    edit (row) {
      let id = row.id
      updateModularApply({
        id: id
      }).then((res) => {
        if (res.data.code === '200') {
          this.$message({
            type: 'success',
            message: '撤销成功!'
          })
          this.modularApplyList(this.page)
        } else {
          this.$message({
            message: res.data.message,
            type: 'error'
          })
        }
      })
      this.modularApplyList(this.page)
    },
    handleSizeChange (e) {
      this.page.pageSize = e
      this.modularApplyList(this.page)
    },
    handleCurrentChange (e) {
      this.page.pageNo = e
      this.modularApplyList(this.page)
      console.log(e)
    }
  },

  mounted () {
    this.modularApplyList(this.page)
  }
}
</script>
<style lang="scss" scoped>
/*.el-table .success-row {*/
/*  background: #f0f9eb;*/
/*}*/
/*::v-deep .el-table .warning-row {*/
/*  background: #f7f7f7;*/
/*}*/
.container {
  padding: 20px;
}
</style>
